@isTest
private class AtomTestSuite {


    private static AtomService activitiesService;
    private static ActivitiesClient ac;
	private static String protocol = 'https';
	private static String lotusServer = 'bluehouseisv.lotus.com';
	private static String userName = 'davecarroll@mailinator.com';
	private static String userPassword = 'Hailey24';
	private static ActivityNode testNode;
	private static AtomBase e;
	
	private static String activityUuid = '596G092106AA5EA3F1905B18C4833C000000';

	private AtomTestSuite() {
 		activitiesService = new AtomService(protocol, lotusServer, userName, userPassword, true);
        ac = new ActivitiesClient(activitiesService);
	}
	 
	static testmethod void mainTest() {
 		activitiesService = new AtomService(protocol, lotusServer, userName, userPassword, true);    
        ac = new ActivitiesClient(activitiesService);
        ac.getAtomService();
        
		Feed f = ac.getActivityByUuid(activityUuid);
		f.toAPP();
		ac.getActivityNodes(activityUuid);
		
		System.debug(LoggingLevel.INFO, ac.createActivity('activity from test suite.'));
		
		ac.createActivity(makeActivity());
		ac.createActivity('test');
		ac.createToDoItem(new ToDoEntry(), 'test');
		 
		e = f.getEntries()[0];
		//ToDoEntry tde = new ToDoEntry();
		//tde.convertToTodo((ActivityEntry)e);
		
		System.debug(LoggingLevel.INFO, e);
		exerciseEntry();
		
		ac.getAuthors(e);  
		ac.getContributors(e);  
		ac.getFeed('/activities/service/atom2/activities');
		//ac.getActivitiesByEmail(new List<String>{'davecarroll@mailinator.com'});
		//ac.getActivitiesByEmail('davecarroll@mailinator.com');
		//ac.getActivitiesBySearch('test');
		//ac.getActivitiesByTag('test');
		ac.getLink('test', e);
		ac.getTags(e, null);
			
		List<ActivityNode> nodes;
		TodoEntry todo = new ToDoEntry();
		todo.convertToToDo((ActivityEntry)f.getentries()[0]);
		exerciseTodo(todo);
		
		f = ac.getActivitiesFeed();
		nodes = ac.getActivitiesByTag('test');
		// This gets the todos on an activity
		nodes = ac.getActivityNodes(activityUuid);
		nodes = ac.getAllActivities();
		System.debug(LoggingLevel.INFO, '\n\nHEY\n\n\n\n\n' +  '\n\n\nNODES: \n' + nodes);
		for (ActivityNode node : nodes) {
			testNode = node;
			exerciseActivityNode();
			//todo = (ToDoEntry)ac.createToDoItem(node);
			break; 
		}
		URI u = new URI();
		AtomTestData.getActivityService();
		
		BluehouseService bhs = ac.getActivityService();
		bhs.getWorkspaceByTitle('Activity Dashboard for Dave Carroll');
		bhs.getActiviesPath();
		System.debug(LoggingLevel.INFO, '\n\n Activities Uri: ' + bhs.getActivitiesUri());
  		System.debug(LoggingLevel.INFO, '\n\n Completed Activities Uri: ' + bhs.getCompletedActivitiesUri());
  		System.debug(LoggingLevel.INFO, '\n\n Tuned Out Activities Uri: ' + bhs.getTunedOutActivitiesUri());
  		System.debug(LoggingLevel.INFO, '\n\n Deleted Activities Uri: ' + bhs.getDeletedActivitiesUri());
  		System.debug(LoggingLevel.INFO, '\n\n Public Activities Uri: ' + bhs.getPublicActivitiesUri());
  		System.debug(LoggingLevel.INFO, '\n\n Everything Uri: ' + bhs.getEverythingUri());
  		System.debug(LoggingLevel.INFO, '\n\n Todo List Uri: ' + bhs.getToDosUri());
  		
		ServiceCollection sc = bhs.getCollection('Activities', 'To Do Items');
		if (sc != null) {
			for (Categories c : sc.categories) {
				c.toAPP();
			} 
		}
		//exerciseFeed(f);
		AtomParser ap = new AtomParser();
		
		ActivityNode an = new ActivityNode('id', new List<String>{'author1', 'author2'}, 'content', new List<String>{ 'contributors1', 'contributors2'},
			Datetime.now(), new List<String> {'tags1', 'tags2'}, 'title', Datetime.now(), 'link', 'activityLink');
		
		f.addAuthor('');
		f.addCategory('');
		f.addContributor('');
		f.insertEntry();
		f.getEntry('id');
		
	}
	
	private static void exerciseTodo(ToDoEntry todo) {
		todo.getPositionElement();
		todo.getAssignedToElement();
		todo.getIconElement();
		todo.getDueDateElement();
		todo.extensionsToAPP();
	}
	
	private static void exerciseFeed(Feed f) {
		f.getEntries();
		f.addEntry();
		f.addEntry(new ActivityEntry());
		f.insertEntry();
		f.insertEntry(new AtomBase());
		f.getEntry('id');
	}
	
	private static void exerciseEntry() {
		if (e == null) return;
		ActivityEntry ae = (ActivityEntry)e;
		ae.getActivityId();
		
		e.getSelfLink().toAPP();
		System.debug(LoggingLevel.INFO, '\n\nLOOK OVER HERE!!!! + \n' + e.getSelfLink().toAPP());
		e.getEditMediaLink('one', 'two');
		e.getEditMediaLink();
		e.getEditLink().toAPP();
		e.getEditLinks();
		e.getEnclosureLink();
		e.getEnclosureLinks();
		e.getAlternateLink('one', 'two');
		e.getAlternateLink().toAPP();
		e.getLink('one');
		e.getAlternateLinks();
		e.getIsDraftElement();
		e.setIsDraft(true);
		e.setEdited('2009-01-27T18:22:56Z');
		e.setEdited(Datetime.now());
		e.getEdited();
		e.setEditedElement(Datetime.now());
		e.getEditedElement();
		e.setUpdated('2009-01-27T18:22:56Z');
		e.setUpdated(Datetime.now());
		e.getUpdated();
		e.setUpdatedElement(Datetime.now());
		e.getUpdatedElement();
		e.getTitleType();
		e.getTitle();
		e.setTitle('one', 'text');
		e.setTitleAsXhtml('one');
		e.setTitleAsHtml('two');
		e.setTitle('title');
		e.setTitleElement(new Text('title')); 
		e.getTitleElement();
		e.getSummaryType();
		e.getSummary();
		e.setSummary('one', 'text');
		e.setSummaryAsXhtml('one');
		e.setSummaryAsHtml('html');
		e.setSummary('summary');
		e.setSummaryElement(new Text('dude'));
		e.getSummaryElement();
		e.setSource(null);
		e.getSourceElement();
		e.getSource();
		e.getRightsType();
		e.getRights(); 
		e.setRights('one', 'text');
		e.setRightsAsXhtml('xhtml');
		e.setRightsAsHtml('html');
		e.setRights('text');
		e.setRightsElement(new Text('element'));
		e.getRightsElement();
		e.setPublished('2009-01-27T18:22:56Z');
		e.setPublished(Datetime.now());
		e.getPublished();
		//e.setPublishedElement(Datetime.now());
		e.getPublishedElement();
		e.addNamespace('prefix', 'namespace');
		e.addLink('one', 'two', 'three', 'four', 'five', 'six');
		e.addLink('one', 'two');
		e.addLink(new Link());
		e.addLink('one');
		e.getLinkElement();
		e.getLinks(new String[]{'one', 'two'});
		e.getLinks('one');
		e.getLinks(); 
		e.setId('one');
		e.getId();
		e.setIdElement('one');
		e.addContributor('one', 'two', 'three');
		e.getContributorElement();
		e.getContributors();
		e.getContentType();
		e.getContentSrc();
		e.getContent();
		e.setContent(new URI('dude'), 'two');
		e.setContent('one', 'text');
		e.setContentAsXhtml('xhtml');
		e.setContentAsHtml('html');
		e.setContent('content');
		e.setContentElement(new Content());
		e.getContentElement();
		e.addCategory('one', 'two', 'three');
		e.addCategory('term');
		e.addCategory(new Category());
		e.getCategoryElement();
		e.getCategories('one');
		e.getCategories();
		e.addAuthor('one', 'two', 'three');
		e.addAuthor('name');
		e.addAuthor(new Person());
		e.getAuthors();
		e.getAuthor();
		e.toAPP();
	} 
			
   	private static void exerciseActivityNode() {
   		if (testNode == null) return;
   		System.debug(LoggingLevel.INFO, '\n\nACTIVITYNODE: \n' + testNode);
   		
		testNode.getAuthor();
		testNode.getContent();
		testNode.getContributors();
		testNode.getPublished();
		testNode.getTags();
		testNode.getTitle();
		testNode.getUpdated();
		testNode.getLink();
		testNode.getWeight();
		testNode.getActivityLink();
		testNode.compareTo(testNode);
		testNode.equals(testNode);
		testNode.compare(testNode, testNode);
		testNode.tosString();
		testNode.addToCommonList('test');
		testNode.incWeight();
		testNode.getCommonList();
		testNode.getActivityPath();
		testNode.getAuthorNames();
		testNode.getId();
		testNode.setCommon(new List<String>{'one', 'two'});
		testNode.setWeight(2); 
		testNode.setUpdated(Datetime.now());
		testNode.setTitle('test');
		testNode.setActivityLink('link');
		testNode.setTags(new List<String>{'one', 'two'});
		testNode.setPublished(Datetime.now());
		testNode.setContributors(new List<String>{'one', 'two'});
		testNode.setContent('content');
		testNode.setAuthors(new List<String>{ 'one', 'two'});
		testNode.setId('id');		
	}
	
	private static ActivityEntry makeActivity() {
		ActivityEntry activity = new ActivityEntry();
		activity.setTitle('This is a new one from test suite.');
		activity.addCategory('http://www.ibm.com/xmlns/prod/sn/type', 'activity', 'Activity');
		activity.addCategory('http://www.ibm.com/xmlns/prod/sn/priority', '2001', 'High');
		activity.addCategory('tag1');
		activity.addCategory('tag2');
		activity.addCategory('tag3');
		activity.setContent('This is the content of my activity'); 
		return activity;
	}
	
}